#ifndef _TYPES_H_
#define _TYPES_H_

/* define the "C language advanced keyword" of the target IDE */
#if defined (__IAR_SYSTEMS_ICC__)
    #define NO_INIT                             __no_init
    #define SECTION(x)                          @ x
    #define UNUSED(x)                           ((void)(x))
    #define USED
    #define PRAGMA(x)                           _Pragma(#x)
    #define ALIGNMENT(n)                        PRAGMA(data_alignment=n)
    #define WEAK                                __weak
    #define STATIC                              static
    #define INLINE                              STATIC inline
    #define RESTRICT                            restrict
#elif defined(__GNUC__)
    #define NO_INIT
    #define SECTION(x)                          __attribute__((section(x)))
    #define UNUSED(x)                           __attribute__((unused))
    #define USED                                __attribute__((used))
    #define PRAGMA(x)
    #define ALIGNMENT(n)                        __attribute__((aligned(n)))
    #define WEAK                                __attribute__((weak))
    #define STATIC                              static
    #define INLINE                              STATIC __inline
    #define RESTRICT                            __restrict
#else
    #define NO_INIT
    #define SECTION(x)
    #define UNUSED(x)
    #define USED
    #define PRAGMA(x)
    #define ALIGNMENT(n)
    #define WEAK
    #define STATIC
    #define INLINE
    #define RESTRICT
#endif    
/******************************************************************************/

/* define the NULL */
#ifndef NULL
    #define NULL                            0
#endif
/******************************************************************************/

/* define the OS data type */
typedef unsigned char                       u8;
typedef unsigned short                      u16;
typedef unsigned int                        u32;
typedef unsigned long long                  u64;
typedef signed char                         s8;
typedef signed short                        s16;
typedef signed int                          s32;
typedef signed long long                    s64;

typedef u8                                  uint8;
typedef u16                                 uint16;
typedef u32                                 uint32;
typedef u64                                 uint64;
typedef s8                                  int8;
typedef s16                                 int16;
typedef s32                                 int32;
typedef s64                                 int64;

typedef u8                                  uint8_t;
typedef u16                                 uint16_t;
typedef u32                                 uint32_t;
typedef u64                                 uint64_t;
typedef s8                                  int8_t;
typedef s16                                 int16_t;
typedef s32                                 int32_t;
typedef s64                                 int64_t;

typedef int                                 err_t;
typedef int                                 loff_t;

typedef unsigned int                        size_t;
typedef signed int                          ssize_t;
#ifndef __cplusplus
    typedef enum {false = 0, true = 1}      bool;
    typedef bool                            BOOL;
#endif
/******************************************************************************/

/* define the hardware data type */
typedef uint32_t                            phys_addr_t;
typedef uint32_t                            phys_reg_t;
typedef volatile phys_reg_t                 rw_reg_t;
typedef const phys_reg_t                    ro_reg_t;
typedef volatile phys_reg_t                 wo_reg_t;

/* define the date type of the time */
typedef uint32_t                            time_t;

/* define the handle of  the thread */
typedef int                                 pthread_t;
typedef int                                 pid_t;

/* define the handle of  the timer */
typedef int                                 timer_t;

/* define the handle of the message queue */
typedef int                                 mqd_t ;
typedef int                                 mode_t;

/******************************************************************************/
    
/* define the data type attribute */
#define OS_U8_MAX                           (255)
#define OS_U8_MIN                           (0)

#define OS_S8_MAX                           (127)
#define OS_S8_MIN                           (-127)

#define OS_U16_MAX                          (65535)
#define OS_U16_MIN                          (0)

#define OS_S16_MAX                          (32767)
#define OS_S16_MIN                          (-32767)

#define OS_U32_MAX                          (4294967295)
#define OS_U32_MIN                          (0)

#define OS_S32_MAX                          (2147483647)
#define OS_S32_MIN                          (-2147483647)
/******************************************************************************/
    
/* define the IO handle declare */
#ifndef __IO
#define __IO                                volatile
#endif

#ifndef __I  
#define __I                                 const
#endif

#ifndef __O
#define __O                                 volatile
#endif

#define OS_RW                               __IO
#define OS_RO                               __I
#define OS_WO                               __O
/******************************************************************************/
    
/* define the memory address align */  
#define __ALIGN(size, align)                (((((phys_addr_t)size) + (align) - 1)) & (~((align) - 1)))

#ifndef PHY_ADDR_REMAP
    #define PHY_ADDR_REMAP(x)               x
#endif

#define ARRAY_SIZE(x)                       sizeof(x) / sizeof(x[0])
/******************************************************************************/

/* type of timer source clock */
enum clockid
{
    CLOCK_REALTIME = 0,
};
typedef enum clockid clockid_t;


#endif
